#include <iostream>
#include "Persion.h"
#include "MysqlUtils.h"


#ifdef __WINDOWS_
#include <windows.h>
#else
#include <unistd.h>
#endif

#include <boost/asio.hpp>

boost::asio::io_service io_service;
boost::posix_time::seconds interval(1); // 1 second
boost::asio::deadline_timer timer(io_service, interval);

void tick(const boost::system::error_code& /*e*/) {

    std::cout << "tick" << std::endl;
    ConnectMysql();//连接数据库
    insertData("insert into student(name,age) values('wenfei',23);");
    QueryDatabase("select * from student order by id desc limit 0,1;");
    FreeConnect();
    // Reschedule the timer for 1 second in the future:
    timer.expires_at(timer.expires_at() + interval);
    // Posts the timer event
    timer.async_wait(tick);
}

int main() {
    std::cout << "Hello, World!" << std::endl;
    std::cout << "Hello, Wenfei!" << std::endl;
    Persion persion("wenfei huang");
    persion.printName();


//    ConnectMysql();//连接数据库
//    insertData("insert into student(name,age) values('wenfei',23);");
//    QueryDatabase("select * from student");
//    updateData("update student SET name='wengui' WHERE age=23;");
//    insertData("insert into student(name,age) values('wenfei',23);");
//    FreeConnect();

    // Schedule the timer for the first time:
    timer.async_wait(tick);
    // Enter IO loop. The timer will fire for the first time 1 second from now:
    io_service.run();
    return 0;
}
